import * as Api from '@/api/system/resource'

const resource = {
  state: {
  },
  mutations: {
  },
  actions: {
    GetResourcePage({ commit }, param) {
      return new Promise((resolve, reject) => {
        Api.getResourcePage(param)
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    GetMenuTree({ commit }) {
      return new Promise((resolve, reject) => {
        Api.getMenuTree()
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    GetResourceById({ commit }, id) {
      return new Promise((resolve, reject) => {
        Api.getResourceById(id)
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    SaveResource({ commit }, data) {
      return new Promise((resolve, reject) => {
        Api.saveResource(data)
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    UpdateResourceById({ commit }, { id, data }) {
      return new Promise((resolve, reject) => {
        Api.updateResourceById(id, data)
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    RemoveResourceById({ commit }, id) {
      return new Promise((resolve, reject) => {
        Api.removeResourceById(id)
          .then(res => {
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    }
  }
}

export default resource
